<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 20px;
        border: 1px solid #000;
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <script>
      // document.getElementsByTagName('标签名') 返回是一个伪数组 标签选择器
      var divs = document.getElementsByTagName("div");
      // 通过遍历得到数组里面的每一个元素  数组里面的每一个元素就代表了一个一个的html标签
      for (var i = 0; i < divs.length; i++) {
        // divs[i].style.backgroundColor = "skyblue";
        if (i % 2 === 0) {
          divs[i].style.backgroundColor = "pink";
        } else {
          divs[i].style.backgroundColor = "skyblue";
        }
      }
    </script>
  </body>
</html>
